package mud

import grails.test.*

import com.unknown.world.Exit;
import com.unknown.world.Room;

class RoomServiceTests extends GroovyTestCase {
	
	def roomService
	
    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testRoomRepository() {
		Room room = new Room(name:"Town Square", description:"Center of Town")
		room = roomService.save( room )
		assert room.id != null

		List<Room> rooms = roomService.findAll()
		assert rooms.size() > 0		
		
		room = roomService.findById(room.id)
		assert room != null
	
		Room west = new Room(name:"Town Square - West", description:"West of Town Square");
		roomService.save(west);
		
		room.exits = new ArrayList()
		room.exits.add( new Exit(name:'West', roomId:west.id) )
		roomService.save(room)
		
		room = roomService.findById(room.id)
		assert room != null
		assert room.exits != null
		assert room.exits.size() > 0
		
		roomService.delete(room);
		roomService.delete(west);
    }
}
